package netJava_part1_nbu2010_lab01_fn51939;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class FunctionClass {

	private List<Student> lstStudents;
	
	public FunctionClass() {
		this.lstStudents = new ArrayList<Student>();
	}
	
	public void addStudentToList(Student student){
		this.lstStudents.add(student);
	}

	public void sortStudentsList(){
		Collections.sort(this.lstStudents, new CompareByMarks());
		Collections.sort(this.lstStudents, new CompareByNumbers());
	}
	
	public List<Student> getlstStudents(){
		return this.lstStudents;
	}
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		Student student;
		Float mark;
		String number;
		FunctionClass test = new FunctionClass();	
		for (int i = 0; i < 10; i++){
			System.out.println("Enter Student Mark");	
			mark = Float.valueOf(in.nextLine());
			System.out.println("Enter Student Number");
			number = in.nextLine();
			student = new Student(number, mark);
			test.addStudentToList(student);
		}
		
		test.sortStudentsList();
		Collections.reverse(test.getlstStudents());
		for(Student st : test.getlstStudents()){
			System.out.println("Mark: " +st.getstudentMarks()+ " / Number: " + st.getstudentFacultyNumber());
		}

	}
	
	private class CompareByMarks implements Comparator<Student> {

		@Override
		public int compare(Student o1, Student o2) {
			return o1.getstudentMarks().compareTo(o2.getstudentMarks());
		}
	}
	
	private class CompareByNumbers implements Comparator<Student> {

		@Override
		public int compare(Student o1, Student o2) {
			int res = o1.getstudentMarks().compareTo(o2.getstudentMarks());
			if (res == 0){
				return (-1) * o1.getstudentFacultyNumber().compareTo(o2.getstudentFacultyNumber());
			}
			
			return res;
		}

	}

}

	